﻿@{
    ViewBag.Title = "WaitingRoom";
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>@ViewBag.Title</title>
    <link href="@Url.Content("~/Content/Site.css")" rel="stylesheet" type="text/css" />
    <script src="@Url.Content("~/Scripts/modernizr-2.0.6-development-only.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/jquery-1.6.2.min.js")" type="text/javascript"></script>

<script type="text/javascript">
    var c = 0;
    var t;
    var timer_is_on = 0;

    var id = @ViewData["roomId"];

    $(document).ready(function () {
        doTimer();
    });

    function doTimer() {
        if (!timer_is_on) {
            timer_is_on = 1;
            waitRoomRefresh();
        }
        return false;
    }

    function waitRoomRefresh() {
        // Send an AJAX request
        $.getJSON("/Game/GetRoomLocations/?roomId=" + id,
            function (data) {
                $("#locationList").empty();
                // On success, 'data' contains a list of rooms of lobby 1.
                $.each(data, function (key, val) {
                    // Format the text to display.
                    var str = '<a href="#">'
                            + 'Lugar: ' + val.Id
                            + ' - Nome: ' + val.Name
                            + ' - Situação: ' + val.State;
                    if (val.LocationPlayer)
                    {
                        str = str + ' - Jogador: ' + val.LocationPlayer.Name;
                    }
                    str = str + '</a>';

                    // Add a list item for the room.
                    $('<li/>', { html: str })
                    .appendTo($('#locationList'));
                });
            });

        t = setTimeout("waitRoomRefresh()", 3000); //refresh de 5 segundos.
        return false;
    }

 
</script> 

</head>
<body>
    <div id="ibody">
        <div class="content-wrapper">
            <h1>@ViewBag.Title</h1>
        </div>

        <h3>Lugares da sala:</h3>
        <div>
            <ul id='locationList' />
        </div>
    </div>
</body>
</html>